#include<stdio.h>
#include<malloc.h>

typedef struct 
{
    int data;
    struct LNode *prior;
    struct LNode *next;
    int freq;
    int order;
}LNode,*Linklist;

int main()
{
    int n,temp;
    scanf("%d;",&n);
    Linklist head;
    head=(Linklist)malloc(sizeof(LNode));
    head->next=NULL;
    Linklist p,q;
    q=head;
    getchar();
    for(int i=0;i<n;i++)
    {
        p=(Linklist)malloc(sizeof(LNode));
        scanf("%d",&p->data);
        p->freq=0;
        p->prior=q;
        q->next=p;
        p->next=NULL;
        q=p;
    }
    p=head->next;
    int count=1;
    while(p)
    {
        scanf("%d",&p->freq);
        p->order=count;
        count++;
        p=p->next;
    }
    int max,maxout,maxpos;
    for(int i=0;i<n;i++)
    {
        Linklist p,q;
        p=head;
        max=-1,maxpos=-1,maxout=-1;
        while(p)
        {
            if(p->freq>max)
            {
                max=p->freq;
                maxout=p->data;
                maxpos=p->order;
                q=p;
            }
            if(p->freq==max && p->order>maxpos)
            {
                max=p->freq;
                maxout=p->data;
                maxpos=p->order;
                q=p;
            }
            p=p->next;
        }
        if(i!=n-1)  printf("%d ",maxout);
        else        printf("%d",maxout);
        q->freq=-1;
    }
}
